package com.ch.home.controller.dishController;

import com.ch.home.bean.Dish;
import com.ch.home.service.serviceImpl.restDishServiceImpl.DishServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * Created by CHEN on 2019/8/26.
 */
@RestController
@RequestMapping("/dish/basic")
public class DishBasicController {


    @Autowired
    DishServiceImpl dishService;

    /**
     * 拿菜品基本预览信息
     *
     * @return
     */
    @PostMapping("/getPreview")
    public HashMap getPreviewInfo(@RequestParam(required = false) String dishTag) {
        HashMap<Object, Object> result;
        result = dishService.getPreview(new Dish(null, null, null, null, dishTag, null));
        return result;
    }

    /**
     * 拿到菜品的全部基本信息
     *
     * @return
     */
    @PostMapping("/getAll")
    public HashMap getAllInfo(@RequestParam(required = false) Integer dishId) {
        HashMap<Object, Object> result;
        result = dishService.getAll(new Dish(dishId, null, null, null, null, null));
        return result;
    }

    /**
     * 添加基本信息
     *
     * @return
     */
    @PostMapping("/add")
    public HashMap addBasicInfo(@RequestParam(required = false) String dishName,
                                @RequestParam(required = false) String dishDescription,
                                @RequestParam(required = false) Integer dishRank,
                                @RequestParam(required = false) String dishTag) {
        HashMap<Object, Object> result;
        result = dishService.add(new Dish(null, dishName, dishDescription, dishRank, dishTag, 0));
        return result;
    }


    /**
     * 更新基本信息,暂时不准备写
     *
     * @return
     */
    @PostMapping("/update")
    public HashMap updateBasicInfo(@RequestParam(required = false) Integer dishId,
                                   @RequestParam(required = false) String dishName,
                                   @RequestParam(required = false) String dishDescription,
                                   @RequestParam(required = false) Integer dishRank,
                                   @RequestParam(required = false) String dishTag,
                                   @RequestParam(required = false) Integer likeNum) {
        HashMap<Object, Object> result;

        result = dishService.update(new Dish(dishId, dishName, dishDescription, dishRank, dishTag, likeNum));


        return result;
    }


}
